package com.jt.controller;

import com.jt.service.FileService;
import com.jt.vo.ImageVO;
import com.jt.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


@RestController  //表示Controller类,同时要求返回值为JSON
@CrossOrigin     // 允许跨域访问
@RequestMapping("/file")
public class FileController {
    @Autowired
    private FileService fileService;

    //图片上传
    @PostMapping("/upload")
    public SysResult upload(MultipartFile file){
      ImageVO imageVO =  fileService.upload(file);
      if (imageVO==null){
          return SysResult.fail();
      }
      return SysResult.success(imageVO);
    }

    //图片删除
    @DeleteMapping("/deleteFile")
    public SysResult daleteFile (String virtualPath){
        fileService.deleteFile(virtualPath);
        return SysResult.success();
    }
}
